package com.example.baselibrary.utlis

import android.os.SystemClock
import android.view.View

/**
 * @author 郑
 * @date 2025/8/5.
 * qq：331758871
 * phone：18979397268
 */
// 带点击状态回调的增强版
class AdvancedSingleClickListener(
    private val interval: Long = 500,
    private val onValidClick: (View) -> Unit, // 有效点击回调
    private val onRejectedClick: (View) -> Unit = {} // 拒绝点击回调（可选）
) : View.OnClickListener {

    private var lastClickTime: Long = 0

    override fun onClick(v: View) {
        val currentTime = SystemClock.elapsedRealtime()

        if (currentTime - lastClickTime >= interval) {
            lastClickTime = currentTime
            onValidClick(v)
        } else {
            onRejectedClick(v)
        }
    }
}
